const {
    parseStudentId
} = require('../../utils/helpers.js');

module.exports = async (ctx, next) => {
    await next();
    if(ctx.params.model==='student' && ctx.response.status===200){
        const { id, name, device} = ctx.response.body;
        const data = {
            device:device.id,
            action:'student-add',
            data:{
                user_id:parseStudentId(id),
                user_name:name,
                user_privilege:'USER',
            }
        };
        await strapi.plugins['content-manager'].services['contentmanager'].add({ model: 'task' }, data, 'task');
    }
};
